﻿using Framework.SqlSugarCore.Abstractions;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Framework.SqlSugarCore
{
	/// <summary>
	/// 单例获取 数据库上下文
	/// </summary>
	public class AsyncLocalDbContextAccessor
	{
		public static AsyncLocalDbContextAccessor Instance { get; } = new();
		public ISqlSugarDbContext? Current
		{
			get => _currentScope.Value;
			set => _currentScope.Value = value;
		}
		public AsyncLocalDbContextAccessor()
		{
			_currentScope = new AsyncLocal<ISqlSugarDbContext?>();
		}
		private readonly AsyncLocal<ISqlSugarDbContext> _currentScope;
	}
}
